<template>
  <el-dialog @close="closeDialog" title="选择编号" :visible.sync="showBh" width="70%" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
      <el-form-item label="总部编号" prop="zbbh">
        <el-input
          v-model="queryParams.zbbh"
          placeholder="请输入总部编号"
          clearable
        />
      </el-form-item>
      <el-form-item label="客户名字" prop="khname">
        <el-input
          v-model="queryParams.kh"
          placeholder="请输入客户名字"
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="wgdList">
      <el-table-column label="总部编号" align="center" prop="zbbh"/>
      <el-table-column label="客户编号" align="center" prop="bh" />
      <el-table-column label="客户" align="center" prop="kh" />
      <el-table-column label="电话" align="center" prop="dh" />
      <el-table-column label="地址" align="center" prop="dz" />
      <el-table-column label="下场时间" align="center" prop="xcsj" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xcsj) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否已下场" align="center" prop="sfyxc">
        <template slot-scope="scope">
          <span>{{scope.row.sfyxc==='Y'?'是':'否'}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="selectData(scope.row)"
          >选择</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { listYwd } from "@/api/gd/ywd";
import { getKhxx } from '@/api/gd/khxx'
export default {
  name: 'BhList',
  props: {
    showBh: {
      type: Boolean
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      wgdList: [],
      total: 0
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {}
      this.handleQuery();
    },
    getList() {
      this.loading = true;
      listYwd(this.queryParams).then(response => {
        this.wgdList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    closeDialog() {
      this.$emit('closeDialog')
    },
    selectData(row) {
      // 通过id进行查询当前客户信息
      getKhxx(row.khid).then(res => {
        if (res.code === 200) {
          let obj = res.data
          obj.zbbh = row.zbbh
          this.$emit("selectData", obj, row)
        }
      })
    },
  }
}
</script>

<style scoped>

</style>
